#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ls (o<<1)
#define rs (o<<1 | 1)

const int N = 2e5+10;
const int INF = 2e18;
int n,m;
int a[N],t[N<<2],lz[N<<2];



// pushup
// build,modify,query

void pushup(int o){
    t[o] = max(t[ls], t[rs]);
}

void build(int s=1, int e=n, int o=1){
    if ( s==e ){
        t[o] = a[s];
        return;
    }

    int mid = (s+e) / 2;
    build(s,mid,ls);
    build(mid+1,e,rs);
    pushup(o);
}

// t[k] = x;
void modify( int k, int b, int s=1, int e=n, int o=1 ){
    if ( s==e ){
        if ( t[o]<b ) t[o] = b;
        return;
    }

    int mid = (s+e) / 2;
    if ( k<=mid ) modify(k,b,s,mid,ls);
    else modify(k,b,mid+1,e,rs);
    pushup(o);
}

int querymax(int l, int r, int s=1, int e=n, int o=1){
    if ( l<=s && e<=r ){
        return t[o];
    } 

    int mid = (s+e) / 2;
    int ans = -INF;
    if ( l<=mid ) ans = max(ans, querymax(l,r,s,mid,ls));
    if ( mid+1<=r ) ans = max(ans, querymax(l,r,mid+1,e,rs));
    
    return ans;
}

signed main(){
    cin >> n >> m;
    for ( int i=1; i<=n; i++ ) cin >> a[i];
    build();

    while(m--){
        char op; cin >> op;
        if ( op=='Q' ){
            int a,b; cin >> a >> b;
            cout << querymax(a,b) << '\n';
        } else {
            int a,b; cin >> a >> b;
            modify(a,b);
            // for ( int j=1; j<=n; j++ ){
            //     printf("t[%d] = %d\n", j, querymax(j,j));
            // }
        }
    }
}